package com.nzx.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class WebConfig extends WebMvcConfigurationSupport {

    @Bean
    WebInterceptor ManageInterceptor() {
        return new WebInterceptor();
    }

    /** 添加接口访问拦截器 */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(ManageInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/**.html")
                .excludePathPatterns("/")
                .excludePathPatterns("/csrf")
                .excludePathPatterns("/**/error")
                .excludePathPatterns("/**/swagger*", "/**/swagger-resources/**", "/**/webjars/**", "/**/v2/**", "/**/swagger-ui.html/**");
    }

    /**
     * 添加静态资源处理器
     * */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry){

        /** 配置静态文件访问路径，静态文件存放在static文件目录下*/
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:META-INF/resources/webjars/");
    }
}
